<template>
    <div>
      <div>
        <el-input style="width: 200px; margin-right: 20px;"  placeholder="查询文件名称" v-model="name"></el-input>
        <el-input style="width: 200px" placeholder="查询类型" v-model="type"></el-input>
        <!-- <el-select v-model="type" clearable placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select> -->
        <el-button type="primary" style="margin-left: 10px" @click="load(1)">查询</el-button>
        <el-button type="info" @click="reset">重置</el-button>
      </div>
      <el-table style="margin-top: 20px;" :data="tableData" stripe :header-cell-style="{ backgroundColor: 'aliceblue', color: '#666' }">
        <el-table-column prop="id" label="序号" width="70" align="center"></el-table-column>
        <el-table-column prop="name" label="文件名称"></el-table-column>
        <el-table-column prop="type" label="类型"></el-table-column>
        <el-table-column prop="address" label="地址">
          <template v-slot="scope">
                <el-button v-if="scope.row.address" type="success" @click="preview(scope.row.address)" >下载</el-button>
            </template>
        </el-table-column>
        <!-- <el-table-column prop="user" label="发布人"></el-table-column> -->
      </el-table> 
      <div style="margin: 10px 0">
        <el-pagination
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-size="pageSize"
            layout="total, prev, pager, next"
            :total="total">
        </el-pagination>
      </div>
    </div>
  </template>
  
  <script>
  
  export default {
    name: "Notice",
    data() {
      return {
        tableData: [],  // 所有的数据
        pageNum: 1,   // 当前的页码
        pageSize: 10,  // 每页显示的个数
        name: '',
        total: 0,
        fileList:[],
        user: JSON.parse(localStorage.getItem('honey-user') || '{}'),
        type: '',
        // options: [{
        //   value: '项目申报书模版',          
        // }, {
        //   value: '项目计划书模版',         
        // }, {
        //   value: '项目开题报告模版',          
        // }, {
        //   value: '项目中期检查模版',          
        // }, {
        //   value: '项目结题报告模版',          
        // }],
      }
    },
    created() {
      this.load()
    },
    methods: {
      preview(url){
            window.open(url)
        },
      reset() {
        this.name = ''
        this.type = ''
        this.load()
      },
      load(pageNum) {  // 分页查询
        if (pageNum)  this.pageNum = pageNum
        this.$request.get('/documents/selectByPage', {
          params: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            name: this.name,
            type: this.type
          }
        }).then(res => {
          this.tableData = res.data.records
          this.total = res.data.total
        })
      },
      handleCurrentChange(pageNum) {
        this.load(pageNum)
      },
    }
  }
  </script>
  
  <style>

  </style>